package arts.spbu.testswing;

/**
 * Created with IntelliJ IDEA.
 * User: pev67021
 * Date: 29.10.12
 * Time: 8:52
 */

public class MatchEntry implements Comparable {

    private int beg;
    private int end;
    private String entry;

    public MatchEntry(int beg, int end, String txt) {
        this.beg = beg;
        this.end = end;
        entry = txt.substring(beg, end);
    }

    public int getBeg() {
        return beg;
    }

    public int getEnd() {
        return end;
    }

    public String getEntry() {
        return entry;
    }

    @Override
    public String toString() {
        return this.beg + "-" + this.end + ": " + entry;
    }

    @Override
    public int compareTo(Object other) {
        if (!(other instanceof MatchEntry)) {
            throw new ClassCastException("Not a valid object!");
        }
        MatchEntry pair2 = (MatchEntry) other;
        if (this.beg > pair2.getBeg())
            return 1;
        if (this.beg < pair2.getBeg())
            return -1;
        if (this.end > pair2.getEnd())
            return 1;
        if (this.end < pair2.getEnd())
            return -1;
        return 0;
    }
}
